using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace BardsTaleMapViewer {
  public class Dungeon {
    public static string [] _dungeonsName = new string [] { "Wine Cellar (Cellar)", "Sewers", "Catacombs", "Harkyn's Castle (Castle)", "Kylearan's Tower (Tower)", "Mangar's Tower (The Tower)" };

    public int _dungeonIndexPlus1;

    public List<DungeonLevel> _levels;

    public Dungeon (int dungeonIndexPlus1) {
      _dungeonIndexPlus1 = dungeonIndexPlus1;

      if ((_dungeonIndexPlus1 < 1) || (_dungeonIndexPlus1 > 6))
        throw new Exception ();

      _levels = new List<DungeonLevel> ();
      int nbLevels = CalcNbLevels (dungeonIndexPlus1);
      for (int i = 1; i <= nbLevels; i++) {
        DungeonLevel level = new DungeonLevel (dungeonIndexPlus1, i);
        _levels.Add (level);
      }
    }

    public string Name {
      get {
        return (GetName (_dungeonIndexPlus1));
      }
    }

    public static string GetName (int dungeonIndexPlus1) {
      return (_dungeonsName [dungeonIndexPlus1 - 1]);
    }

    public static int DungeonsToLevsIndex (int dungeonIndexPlus1) {
      return (Game._dumpAtari.ReadByte (0x32E4A + dungeonIndexPlus1));
    }

    public static int CalcNbLevels (int dungeonIndexPlus1) {
      int levsIndex = DungeonsToLevsIndex (dungeonIndexPlus1);
      int levsIndexNext = DungeonsToLevsIndex (dungeonIndexPlus1 + 1);
      if (levsIndexNext == 0)
        levsIndexNext = 15 + 1;
      return (levsIndexNext - levsIndex);
    }
  }
}
